package com.garlic.face.jlf.utils;

import android.content.Context;
import android.util.Log;

import com.alipay.zoloz.smile2pay.service.Zoloz;
import com.garlic.face.jlf.App;
import com.garlic.face.jlf.transaction.Means;

import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

/**
 * 刷脸支付的配置项...
 */
public class ZolozUtils {
    private static ZolozUtils mInstance;
    private Zoloz mZoloz;
    private Context mContext;

    public static final String KEY_INIT_RESP_NAME = "zim.init.resp";

    // 值为"1000"调用成功
    // 值为"1003"用户选择退出
    // 值为"1004"超时
    // 值为"1005"用户选用其他支付方式
    public static final String CODE_SUCCESS = "1000";
    public static final String CODE_EXIT = "1003";
    public static final String CODE_TIMEOUT = "1004";
    public static final String CODE_OTHER_PAY = "1005";

    public static final String TXT_EXIT = "已退出刷脸支付";
    public static final String TXT_TIMEOUT = "操作超时";
    public static final String TXT_OTHER_PAY = "已退出刷脸支付";
    public static final String TXT_OTHER = "抱歉未支付成功，请重新支付";

    //刷脸支付相关
    public static final String SMILEPAY_CODE_SUCCESS = "10000";
    public static final String SMILEPAY_SUBCODE_LIMIT = "ACQ.PRODUCT_AMOUNT_LIMIT_ERROR";
    public static final String SMILEPAY_SUBCODE_BALANCE_NOT_ENOUGH = "ACQ.BUYER_BALANCE_NOT_ENOUGH";
    public static final String SMILEPAY_SUBCODE_BANKCARD_BALANCE_NOT_ENOUGH = "ACQ.BUYER_BANKCARD_BALANCE_NOT_ENOUGH";

    public static final String SMILEPAY_TXT_LIMIT = "刷脸支付超出限额，请选用其他支付方式";
    public static final String SMILEPAY_TXT_EBALANCE_NOT_ENOUGH = "账户余额不足，支付失败";
    public static final String SMILEPAY_TXT_BANKCARD_BALANCE_NOT_ENOUGH = "账户余额不足，支付失败";
    public static final String SMILEPAY_TXT_FAIL = "抱歉未支付成功，请重新支付";
    public static final String SMILEPAY_TXT_SUCCESS = "刷脸支付成功";


    private ZolozUtils(Context ctx) {
        this.mContext = ctx;
    }

    public static ZolozUtils getInstance(Context ctx) {
        if (mInstance == null) {
            mInstance = new ZolozUtils(ctx);
            mInstance.init();
        }
        return mInstance;
    }

    private void init() {
        mZoloz = Zoloz.getInstance(x.app());
        mZoloz.zolozInstall(getMerchantInfo());
    }

    public Zoloz getZoloz(Context ctx) {
        if (mInstance == null) {
            mInstance = new ZolozUtils(ctx);
            mInstance.init();
        }
        return mZoloz;
    }

    /**
     * 设备基本信息参数
     *
     * @return 返回 map
     */
    public Map<String, String> getMerchantInfo() {
        //AuthBean authBean = App.getUserInfo();

        Map<String, String> merchantInfo = new HashMap<>();
        //以下信息请根据真实情况填写
        //商户id
        merchantInfo.put("partnerId", App.getPartnerId());
        merchantInfo.put("merchantId", App.getPartnerId());
        //开放平台注册的appid
        merchantInfo.put("appId", /*authBean.getApp_id()*/App.getAppId());
        //机具编号，便于关联商家管理的机具
        merchantInfo.put("deviceNum", /*authBean.getDevice_num()*/(String)Tools.getPref(App.CONFIG_INFO,App.DEVICE_NUM,""));
        //真实店铺号
        merchantInfo.put("storeCode", /*authBean.getAli_store_id()*/(String)Tools.getPref(App.CONFIG_INFO, App.SHOP_NO, ""));
        //口碑店铺号
        //merchantInfo.put("alipayStoreCode", authBean.getKoubei_store_id());
        //品牌，传入拼音或者英文，标示该商家
        merchantInfo.put("brandCode", /*authBean.getStoreName()*/"Carrefour");
//        merchantInfo.put("areaCode", "TEST");
//        merchantInfo.put("geo", "0.000000,0.000000");
//        merchantInfo.put("wifiMac", "TEST");
//        merchantInfo.put("wifiName", "TEST");
//        merchantInfo.put("deviceMac", "TEST");

        Log.e("RAG", merchantInfo.toString());
        return merchantInfo;
    }

}
